function formatOption(options) {
	return {
		success: () => {},
		error: () => {},
		fail: () => {},
		complete: () => {},
		task: () => {},
		header: {},
		...options,
	}
}
/**
 * 下载的函数
 * @param {string} url 下载地址
 */
export function donwload(url = "", options = {}) {
	options = formatOption(options)

	const downloadTask = uni.downloadFile({
		url,
		success: ({ statusCode, tempFilePath }) => {
			if (statusCode === 200) {
				options.success(tempFilePath)
			} else {
				options.fail(statusCode)
				options.error(statusCode)
			}
		},
		complete: (...result) => {
			options.complete(...result)
		},
	})

	downloadTask.onProgressUpdate(({ progress, totalBytesWritten, totalBytesExpectedToWrite }) => {
		options.task(progress, totalBytesWritten, totalBytesExpectedToWrite, downloadTask)
	})
}
